{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 图片颜色反转 0-255 -> 255-当前\n",
    "## 灰色图片的颜色反转\n",
    "import cv2\n",
    "import numpy as np\n",
    "img = cv2.imread('../../imags/test.jpeg',1) \n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n",
    "dst = np.zeros((height,width,1),np.uint8)\n",
    "for i in range(0,height):\n",
    "    for j in range(0,width):\n",
    "        grayPixel = gray[i,j]\n",
    "        dst[i,j] = 255 - grayPixel\n",
    "cv2.imshow('dst',dst)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## 图片颜色反转 0-255 -> 255-当前\n",
    "## 彩色图片的颜色反转，类似相机底板\n",
    "import cv2\n",
    "import numpy as np\n",
    "img = cv2.imread('../../imags/test.jpeg',1) \n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "dst = np.zeros((height,width,3),np.uint8)\n",
    "for i in range(0,height):\n",
    "    for j in range(0,width):\n",
    "        #grayPixel = gray[i,j]\n",
    "        (b,g,r) = img[i,j]\n",
    "        dst[i,j] = (255-b,255-g,255-r)\n",
    "cv2.imshow('dst',dst)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 马赛克效果\n",
    "import cv2\n",
    "import numpy as np\n",
    "img = cv2.imread('../../imags/test.jpeg',1) \n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "for m in range(200,700):\n",
    "    for n in range(200,450):\n",
    "        # pixe -> 10*10\n",
    "        if m%10==0 and n%10==0:\n",
    "            for i in range(0,10):\n",
    "                for j in range(0,10):\n",
    "                    (b,g,r) = img[m,n]\n",
    "                    img[m+i,n+j] = (b,g,r)\n",
    "cv2.imshow('img',img)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 毛玻璃效果\n",
    "import cv2\n",
    "import numpy as np\n",
    "import random\n",
    "img = cv2.imread('../../imags/test.jpeg',1) \n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "dst = np.zeros((height,width,3),np.uint8)\n",
    "mm = 8\n",
    "for m in range(0,height-mm):\n",
    "    for n in range(0,width-mm):\n",
    "        index = int(random.random()*mm)\n",
    "        (b,g,r) = img[m+index,n+index]\n",
    "        dst[m,n] = (b,g,r)\n",
    "cv2.imshow('img',dst)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 图片融合\n",
    "###。。。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "### 边缘检测\n",
    "import cv2\n",
    "import numpy as np\n",
    "import random\n",
    "img = cv2.imread('../../imags/test.jpeg',1) \n",
    "imgInfo = img.shape\n",
    "height = imgInfo[0]\n",
    "width = imgInfo[1]\n",
    "cv2.imshow('src',img)\n",
    "# canny 1.gray 2.高斯 3.canny\n",
    "gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)\n",
    "imgG = cv2.GaussianBlur(gray,(3,3),0)  ##高斯滤波 1，图像数据  2，模板大小\n",
    "dst = cv2.Canny(img,50,50)  ##1 data  2.th 图片经过卷积运算后大于这个点认为是边缘点\n",
    "cv2.imshow('dst',dst)\n",
    "cv2.waitKey(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
